using System.Web.UI;
using System.Web.UI.WebControls;

namespace OpenWaves.Web.Controls
{
    public class OptionalContentPlaceholder : PlaceHolder
    {
        private object dataItem;
        public object DataItem
        {
            get { return this.dataItem; }
            set
            {
                this.dataItem = value;
                this.ShowContent = value != null;
            }
        }

        protected bool ShowContent
        {
            get { return (bool?) this.ViewState["ShowContent"] ?? true; }
            set { this.ViewState["ShowContent"] = value; }
        }

        protected override void DataBindChildren()
        {
            if (this.ShowContent)
                base.DataBindChildren();
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (this.ShowContent)
                base.Render(writer);
        }
    }
}